<template>
	<div class="edit">
		<about-tag
			:query-form="queryForm"
			:character="false"
			v-if="flag===true"
			@save-form="saveForm"
		>
			<template slot="radio">
				<el-radio label="R" v-if="queryForm.labelProperty == 'R'">单选</el-radio>
				<el-radio label="C" v-if="queryForm.labelProperty == 'C'">复选</el-radio>
			</template>
		</about-tag>
	</div>
</template>

<script>
	import AboutTag from "../components/about-tag.vue";
	import tagApi from "../../../apis/rc/tag.mjs";
	export default {
		name: "edit",
		components: { AboutTag },
		data() {
			return {
				queryForm: {
					name: "", //标签名称
					applyScopes: ["C"], //适用范围
					isRequired: "N", //是否必填
					availableState: "Y", //状态
					labelProperty: "", //标签属性
					labelDetails: [{ name: "" }, { name: "" }], //标签值
					remark: "", //备注说明
					labelProjectRelations: []
				},
				flag: false
			};
		},
		methods: {
			//查询页面数据
			onQueryForm(id) {
				let params = {};
				params.id = id;
				tagApi.showTableDataItem({
					data: params,
					success: (res) => {
						this.queryForm = { ...this.queryForm, ...res };
						this.queryForm.labelProjectRelations = res.projects.map((i) => i.projectId);
						let index = 0;
						this.queryForm.labelDetails.forEach((item) => {
							index += 1;
							item.index = index;
						});
					},
					complete: () => {
						this.flag = true;
					}
				});
			},
			saveForm(data) {
				tagApi.editSourseTag({
					data: data,
					success: () => {
						nlapp.PageUtil.navigateToOnly("/rc/tag/list");
					},
					complete: () => {}
				});
			}
		},
		created() {
			let id = this.$route.query.id;
			this.onQueryForm(id);
		}
	};
</script>